package com.lp.multi.thread.example04;

/**
 * @author: lp
 * @create: 2021-06-21 16:41
 * @description: TODO
 */
public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            String threadName = Thread.currentThread().getName();
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(threadName+"线程已结束");
        });

        Thread.State state = thread.getState();
        System.out.println("state = " + state);//NEW
        thread.start();
        state = thread.getState();
        System.out.println("state = " + state);//RUNNABLE
        while (!Thread.State.TERMINATED.equals(state)){
            Thread.sleep(100);
            state = thread.getState();
            System.out.println("state = " + state);
        }

    }
}
